{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/root/mambaforge/envs/dl4/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "If for detection, please install mmdetection first\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "# cwd = os.getcwd()\n",
    "# parent_dir = os.path.dirname(cwd)\n",
    "\n",
    "import sys\n",
    "sys.path.append('../')  \n",
    "from fasternet import models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "import yaml\n",
    "from argparse import Namespace\n",
    "from timm import create_model\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_cfg(cfg):\n",
    "    hyp = None\n",
    "    if isinstance(cfg, str):\n",
    "        with open(cfg, errors='ignore') as f:\n",
    "            hyp = yaml.safe_load(f)  # load hyps dict\n",
    "    return hyp\n",
    "    # return Namespace(**hyp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'strategy': 'ddp', 'benchmark': True, 'pretrained': False, 'sync_batchnorm': False, 'dataset_name': 'imagenet', 'image_size': 224, 'multi_scale': '192_280', 'test_crop_ratio': 0.9, 'opt': 'adamw', 'weight_decay': 0.005, 'momentum': 0.9, 'epochs': 300, 'clip_grad': None, 'precision': 16, 'sched': 'cosine', 'lr': 0.004, 'warmup_lr': 1e-06, 'min_lr': 1e-05, 'warmup_epochs': 20, 'teacher_model': 'regnety_160', 'distillation_type': 'none', 'distillation_alpha': 0.5, 'distillation_tau': 1.0, 'model_name': 'fasternet', 'mlp_ratio': 2, 'embed_dim': 40, 'depths': [1, 2, 8, 2], 'feature_dim': 1280, 'patch_size': 4, 'patch_stride': 4, 'patch_size2': 2, 'patch_stride2': 2, 'layer_scale_init_value': 0, 'drop_path_rate': 0.0, 'norm_layer': 'BN', 'act_layer': 'GELU', 'n_div': 4, 'color_jitter': 0, 'aa': None, 'train_interpolation': 'bicubic', 'smoothing': 0.1, 'reprob': 0, 'remode': 'pixel', 'recount': 1, 'mixup': 0.05, 'cutmix': 1.0, 'cutmix_minmax': None, 'mixup_prob': 1.0, 'mixup_switch_prob': 0.5, 'mixup_mode': 'batch'}\n"
     ]
    }
   ],
   "source": [
    "args = load_cfg('/root/code/cvmark/face/cls/fasternet/cfg/fasternet_t0.yaml')\n",
    "print(args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a': 1, 'b': 2}\n"
     ]
    }
   ],
   "source": [
    "def func(**kwargs):\n",
    "    print(kwargs)\n",
    "\n",
    "dic = {'a': 1, 'b': 2}\n",
    "func(**dic)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'fasternet'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "args.model_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'Namespace' object is not iterable",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m/root/code/cvmark/face/cls/demo/use_fasternet.ipynb Cell 7\u001b[0m line \u001b[0;36m1\n\u001b[0;32m----> <a href='vscode-notebook-cell://ssh-remote%2Btlh/root/code/cvmark/face/cls/demo/use_fasternet.ipynb#X11sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a>\u001b[0m \u001b[39mdict\u001b[39;49m(args)\n",
      "\u001b[0;31mTypeError\u001b[0m: 'Namespace' object is not iterable"
     ]
    }
   ],
   "source": [
    "dict(args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "fnet = create_model(**args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FasterNet(\n",
       "  (patch_embed): PatchEmbed(\n",
       "    (proj): Conv2d(3, 40, kernel_size=(4, 4), stride=(4, 4), bias=False)\n",
       "    (norm): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "  )\n",
       "  (stages): Sequential(\n",
       "    (0): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(40, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(80, 40, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(10, 10, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "    (1): PatchMerging(\n",
       "      (reduction): Conv2d(40, 80, kernel_size=(2, 2), stride=(2, 2), bias=False)\n",
       "      (norm): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    )\n",
       "    (2): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(80, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(160, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(20, 20, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (1): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(80, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(160, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(20, 20, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "    (3): PatchMerging(\n",
       "      (reduction): Conv2d(80, 160, kernel_size=(2, 2), stride=(2, 2), bias=False)\n",
       "      (norm): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    )\n",
       "    (4): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (1): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (2): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (3): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (4): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (5): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (6): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (7): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "    (5): PatchMerging(\n",
       "      (reduction): Conv2d(160, 320, kernel_size=(2, 2), stride=(2, 2), bias=False)\n",
       "      (norm): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    )\n",
       "    (6): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(320, 640, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(640, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(640, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (1): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(320, 640, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(640, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(640, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "  )\n",
       "  (avgpool_pre_head): Sequential(\n",
       "    (0): AdaptiveAvgPool2d(output_size=1)\n",
       "    (1): Conv2d(320, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "    (2): GELU(approximate='none')\n",
       "  )\n",
       "  (head): Linear(in_features=1280, out_features=1000, bias=True)\n",
       ")"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fnet"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<All keys matched successfully>"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weight_path = '/root/code/cvmark/face/cls/fasternet/weights/fasternet_t2-epoch.289-val_acc1.78.8860.pth'\n",
    "weight_path = '/root/code/cvmark/face/cls/fasternet/weights/fasternet_t0-epoch.281-val_acc1.71.9180.pth'\n",
    "fnet.load_state_dict(torch.load(weight_path))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[fasternet.models.fasternet.FasterNet, torch.nn.modules.module.Module, object]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fnet.__class__.mro()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "fnet1 = models.fasternet(**args)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "FasterNet(\n",
       "  (patch_embed): PatchEmbed(\n",
       "    (proj): Conv2d(3, 40, kernel_size=(4, 4), stride=(4, 4), bias=False)\n",
       "    (norm): BatchNorm2d(40, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "  )\n",
       "  (stages): Sequential(\n",
       "    (0): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(40, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(80, 40, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(10, 10, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "    (1): PatchMerging(\n",
       "      (reduction): Conv2d(40, 80, kernel_size=(2, 2), stride=(2, 2), bias=False)\n",
       "      (norm): BatchNorm2d(80, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    )\n",
       "    (2): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(80, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(160, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(20, 20, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (1): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(80, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(160, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(20, 20, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "    (3): PatchMerging(\n",
       "      (reduction): Conv2d(80, 160, kernel_size=(2, 2), stride=(2, 2), bias=False)\n",
       "      (norm): BatchNorm2d(160, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    )\n",
       "    (4): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (1): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (2): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (3): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (4): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (5): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (6): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (7): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(160, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(320, 160, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(40, 40, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "    (5): PatchMerging(\n",
       "      (reduction): Conv2d(160, 320, kernel_size=(2, 2), stride=(2, 2), bias=False)\n",
       "      (norm): BatchNorm2d(320, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "    )\n",
       "    (6): BasicStage(\n",
       "      (blocks): Sequential(\n",
       "        (0): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(320, 640, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(640, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(640, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "        (1): MLPBlock(\n",
       "          (drop_path): Identity()\n",
       "          (mlp): Sequential(\n",
       "            (0): Conv2d(320, 640, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "            (1): BatchNorm2d(640, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)\n",
       "            (2): GELU(approximate='none')\n",
       "            (3): Conv2d(640, 320, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "          )\n",
       "          (spatial_mixing): Partial_conv3(\n",
       "            (partial_conv3): Conv2d(80, 80, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)\n",
       "          )\n",
       "        )\n",
       "      )\n",
       "    )\n",
       "  )\n",
       "  (avgpool_pre_head): Sequential(\n",
       "    (0): AdaptiveAvgPool2d(output_size=1)\n",
       "    (1): Conv2d(320, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False)\n",
       "    (2): GELU(approximate='none')\n",
       "  )\n",
       "  (head): Linear(in_features=1280, out_features=1000, bias=True)\n",
       ")"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fnet1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "dl4",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
